package com.tongzhou.client;

import java.io.UnsupportedEncodingException;

import net.sf.json.JSONObject;

import com.tongzhou.db.exception.DBException;
import com.tongzhou.tongzhou.account.dao.IAccountDAO;
import com.tongzhou.tongzhou.account.dao.impl.AccountDAO;
import com.tongzhou.tongzhou.account.model.Client;

//注册接口
public class ClientRegist {
	IAccountDAO dao=new AccountDAO();
	Client client=null;
	public String getInfo(String json){
		JSONObject jsonObject = JSONObject.fromObject( json );
		String companyName=null;
		String contactCall=null;
		if(jsonObject.get("companyName")!=null){
			companyName=(String) jsonObject.get( "companyName");
//			try {
//				companyName=new String(companyName.getBytes("ISO-8859-1"),"UTF-8");
//			} catch (UnsupportedEncodingException e) {
//				e.printStackTrace();
//			}
		}
		if(jsonObject.get("contactCall")!=null){
			contactCall=(String) jsonObject.get( "contactCall");
		}
		if(companyName==null||contactCall==null){
			return "{'success':0,'msg':'输入参数有误!'}";
		}else{
			client=new Client();
			try {
				client.setCompany_name(companyName);
				client.setContact_call(contactCall);
				dao.addClient(client);
				String str="{'success':1,'msg':'注册成功!'}";
				return str;
			} catch (DBException e) {
				e.printStackTrace();
			}
		}
		return "{'success':0,'msg':'注册失败!'}";
	}
}
